package me.wz.util.sdbc;

public interface IIntercept {
    public String onPrepareStatement(String sql);

    static class Helper {
        private IIntercept intcpt;
        private ThreadLocal<IIntercept> tlIntcpt = new ThreadLocal<>();

        public String onPrepareStatement(String sql) {
            try {
                String ret = sql;
                if( intcpt != null ) {
                    ret = intcpt.onPrepareStatement(ret);
                }
                if( tlIntcpt.get() != null ) {
                    ret = tlIntcpt.get().onPrepareStatement(ret);
                }
                return ret;
            }
            finally {
                intcpt = null;
            }
        }

        public IIntercept getIntcpt() {
            return intcpt;
        }

        public void setIntcpt(IIntercept intcpt) {
            this.intcpt = intcpt;
        }

        public IIntercept getTlIntcpt() {
            return tlIntcpt.get();
        }

        public void setTlIntcpt(IIntercept tlIntcpt) {
            this.tlIntcpt.set(tlIntcpt);
        }
    }
}
